<template>
	<view ref="container" class="goodscollection">
		<view class="collectionGoods" v-if="collectProductList.length > 0">
			<view class="item acea-row row-between-wrapper"
				v-for="(item, collectProductListIndex) in collectProductList" :key="collectProductListIndex"
				@click="goGoodsCon(item)">
				<view class="pictrue">
					<image :src="item.image" />
				</view>
				<view class="text acea-row row-column-between">
					<view class="infor line1">{{ item.storeName }}</view>
					<view class="acea-row row-between-wrapper">
						<view class="money font-color-red">￥{{ item.price }}</view>
						<text class="iconfont icon-shanchu" @tap.stop="delCollection(collectProductListIndex)"></text>
					</view>
				</view>
			</view>
		</view>
		<Loading :loaded="loadend" :loading="loading"></Loading>
		<view class="noCommodity" v-if="collectProductList.length < 1 && page > 1">
			<view class="noPictrue">
				<image src="https://h5.ylsp.vip/file/static/record-bg.png" class="image" />
			</view>
		</view>
	</view>
</template>
<script>
	import {
		getCollectUser,
		getCollectDel
	} from "@/api/user";
	import Loading from "@/components/Loading";
	export default {
		name: "GoodsCollection",
		components: {
			Loading
		},
		props: {},
		data: function() {
			return {
				page: 1,
				limit: 20,
				type: 'collect',
				collectProductList: [],
				loadTitle: "",
				loading: false,
				loadend: false
			};
		},
		mounted: function() {
			this.get_user_collect_product();
		},
		onReachBottom() {
			!this.loading && this.get_user_collect_product();
		},
		methods: {
			goGoodsCon(item) {
				this.$yrouter.push({
					path: "/pages/shop/GoodsCon/index",
					query: {
						id: item.pid
					}
				});
			},
			get_user_collect_product: function() {
				let that = this;
				if (that.loading) return;
				if (that.loadend) return;
				that.loading = true;
				getCollectUser(that.page, that.limit, that.type).then(res => {
					that.loading = false;
					that.collectProductList.push.apply(that.collectProductList, res.data);
					that.loadend = res.data.length < that.limit;
					that.page = that.page + 1;
				});
			},
			delCollection: function(index) {
				let that = this,
					id = that.collectProductList[index].pid,
					category = "collect";
				getCollectDel(id, category).then(function() {
					uni.showToast({
						title: "删除成功",
						icon: "success",
						duration: 2000,
						complete: () => {
							that.collectProductList.splice(index, 1);
							that.$set(that, "collectProductList", that.collectProductList);
						}
					});
				});
			}
		}
	};
</script>
